package com.yugao.fintech.draper.admin.controller;

import cn.hutool.json.JSONArray;
import com.yugao.fintech.draper.admin.service.RouteConfigService;
import com.yugao.fintech.draper.auth.dto.RouteConfVO;
import com.yugao.fintech.draper.core.model.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/routeConf")
@RequiredArgsConstructor
@Tag(name = "路由配置管理")
public class RouteConfigController {

	private final RouteConfigService routeConfigService;

	@Operation(summary = "获取全部路由信息")
	@GetMapping(value = "/findAll")
	public ResultVO<List<RouteConfVO>> findAll() {
		return ResultVO.success(routeConfigService.findAll());
	}

	@Operation(summary = "添加路由信息")
	@PostMapping(value = "/add")
	public ResultVO<Boolean> add(@RequestBody RouteConfVO routeConfVo) {
		return ResultVO.success(routeConfigService.addRouteConf(routeConfVo));
	}

	@Operation(summary = "修改路由信息")
	@PutMapping(value = "/update")
	public ResultVO<Boolean> update(@RequestBody JSONArray routeConf) {
		return ResultVO.success(routeConfigService.updateRouteConf(routeConf));
	}

	@Operation(summary = "删除路由信息")
	@DeleteMapping(value = "/delete")
	public ResultVO<Boolean> delete(Long id) {
		return ResultVO.success(routeConfigService.deleteRouteConf(id));
	}

	@Operation(summary = "获取单条路由信息")
	@GetMapping(value = "/findById")
	public ResultVO<RouteConfVO> findById(Long id) {
		return ResultVO.success(routeConfigService.findById(id));
	}
}